package com.edu.exam.entity.grading;

import com.edu.exam.enums.grading.StatType;
import com.edu.exam.enums.grading.DataSource;
import com.edu.exam.enums.grading.DataCompleteness;
import com.edu.exam.enums.grading.CalculationStatus;
import com.edu.exam.enums.grading.ValidationStatus;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 批阅统计实体类
 * [所属模块] E-04 扫描阅卷处理模块
 *
 * 根据E-04-05 网上批阅子模块设计实现
 * 对应grading_statistics数据表
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "grading_statistics",
    uniqueConstraints = {
        @UniqueConstraint(columnNames = {"teacher_id", "exam_id", "stat_date", "stat_type"})
    })
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
public class GradingStatistics {

    @Id
    @Column(name = "stat_id", length = 64)
    private String statId;

    /**
     * 教师ID
     */
    @Column(name = "teacher_id", nullable = false, length = 64)
    private String teacherId;

    /**
     * 考试ID
     */
    @Column(name = "exam_id", nullable = false, length = 64)
    private String examId;

    /**
     * 统计日期
     */
    @Column(name = "stat_date", nullable = false)
    private LocalDate statDate;

    /**
     * 统计类型：DAILY（日统计）、WEEKLY（周统计）、MONTHLY（月统计）、EXAM（考试统计）、TASK（任务统计）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "stat_type", nullable = false, length = 32)
    private StatType statType;

    /**
     * 批阅总数
     */
    @Column(name = "total_graded", nullable = false)
    private Integer totalGraded;

    /**
     * 平均分
     */
    @Column(name = "avg_score", precision = 5, scale = 2)
    private Double avgScore;

    /**
     * 最高分
     */
    @Column(name = "max_score", precision = 5, scale = 2)
    private Double maxScore;

    /**
     * 最低分
     */
    @Column(name = "min_score", precision = 5, scale = 2)
    private Double minScore;

    /**
     * 分数中位数
     */
    @Column(name = "median_score", precision = 5, scale = 2)
    private Double medianScore;

    /**
     * 分数标准差
     */
    @Column(name = "score_std_deviation", precision = 5, scale = 2)
    private Double scoreStdDeviation;

    /**
     * 平均每张图像耗时（秒）
     */
    @Column(name = "avg_time_per_image")
    private Integer avgTimePerImage;

    /**
     * 最短批阅时间（秒）
     */
    @Column(name = "min_time_per_image")
    private Integer minTimePerImage;

    /**
     * 最长批阅时间（秒）
     */
    @Column(name = "max_time_per_image")
    private Integer maxTimePerImage;

    /**
     * 批阅时间中位数（秒）
     */
    @Column(name = "median_time_per_image")
    private Integer medianTimePerImage;

    /**
     * 质量评分
     */
    @Column(name = "quality_score", precision = 5, scale = 2)
    private Double qualityScore;

    /**
     * 效率评分
     */
    @Column(name = "efficiency_score", precision = 5, scale = 2)
    private Double efficiencyScore;

    /**
     * 准确性评分
     */
    @Column(name = "accuracy_score", precision = 5, scale = 2)
    private Double accuracyScore;

    /**
     * 一致性评分
     */
    @Column(name = "consistency_score", precision = 5, scale = 2)
    private Double consistencyScore;

    /**
     * 批注数量
     */
    @Column(name = "annotation_count")
    private Integer annotationCount;

    /**
     * 平均每张图像批注数量
     */
    @Column(name = "avg_annotations_per_image", precision = 5, scale = 2)
    private Double avgAnnotationsPerImage;

    /**
     * 修改次数
     */
    @Column(name = "modification_count")
    private Integer modificationCount;

    /**
     * 重批次数
     */
    @Column(name = "re_grading_count")
    private Integer reGradingCount;

    /**
     * 协作批阅次数
     */
    @Column(name = "collaborative_grading_count")
    private Integer collaborativeGradingCount;

    /**
     * 质检通过数量
     */
    @Column(name = "quality_check_passed_count")
    private Integer qualityCheckPassedCount;

    /**
     * 质检失败数量
     */
    @Column(name = "quality_check_failed_count")
    private Integer qualityCheckFailedCount;

    /**
     * 质检通过率（0-100）
     */
    @Column(name = "quality_check_pass_rate", precision = 5, scale = 2)
    private Double qualityCheckPassRate;

    /**
     * 详细指标（JSON格式）
     */
    @Column(name = "detailed_metrics", length = 3000, columnDefinition = "TEXT")
    private String detailedMetrics;

    /**
     * 时间分布数据（JSON格式）
     */
    @Column(name = "time_distribution", length = 2000, columnDefinition = "TEXT")
    private String timeDistribution;

    /**
     * 分数分布数据（JSON格式）
     */
    @Column(name = "score_distribution", length = 2000, columnDefinition = "TEXT")
    private String scoreDistribution;

    /**
     * 难度分布数据（JSON格式）
     */
    @Column(name = "difficulty_distribution", length = 2000, columnDefinition = "TEXT")
    private String difficultyDistribution;

    /**
     * 题型分布数据（JSON格式）
     */
    @Column(name = "question_type_distribution", length = 2000, columnDefinition = "TEXT")
    private String questionTypeDistribution;

    /**
     * 工作时段统计（JSON格式）
     */
    @Column(name = "working_hours_stats", length = 2000, columnDefinition = "TEXT")
    private String workingHoursStats;

    /**
     * 批注类型统计（JSON格式）
     */
    @Column(name = "annotation_type_stats", length = 2000, columnDefinition = "TEXT")
    private String annotationTypeStats;

    /**
     * 错误统计（JSON格式）
     */
    @Column(name = "error_statistics", length = 2000, columnDefinition = "TEXT")
    private String errorStatistics;

    /**
     * 性能指标（JSON格式）
     */
    @Column(name = "performance_indicators", length = 2000, columnDefinition = "TEXT")
    private String performanceIndicators;

    /**
     * 对比数据（JSON格式）
     */
    @Column(name = "comparison_data", length = 2000, columnDefinition = "TEXT")
    private String comparisonData;

    /**
     * 趋势数据（JSON格式）
     */
    @Column(name = "trend_data", length = 2000, columnDefinition = "TEXT")
    private String trendData;

    /**
     * 异常数据（JSON格式）
     */
    @Column(name = "anomaly_data", length = 2000, columnDefinition = "TEXT")
    private String anomalyData;

    /**
     * 改进建议（JSON格式）
     */
    @Column(name = "improvement_suggestions", length = 2000, columnDefinition = "TEXT")
    private String improvementSuggestions;

    /**
     * 统计周期开始时间
     */
    @Column(name = "period_start_time")
    private LocalDateTime periodStartTime;

    /**
     * 统计周期结束时间
     */
    @Column(name = "period_end_time")
    private LocalDateTime periodEndTime;

    /**
     * 数据来源：SYSTEM（系统自动）、MANUAL（手动输入）、API（API接口）、IMPORT（数据导入）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "data_source", length = 32)
    private DataSource dataSource;

    /**
     * 数据完整性标识：COMPLETE（完整）、PARTIAL（部分）、INCOMPLETE（不完整）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "data_completeness", length = 16)
    private DataCompleteness dataCompleteness;

    /**
     * 计算状态：PENDING（待计算）、CALCULATING（计算中）、COMPLETED（已完成）、FAILED（失败）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "calculation_status", length = 32)
    private CalculationStatus calculationStatus;

    /**
     * 计算耗时（毫秒）
     */
    @Column(name = "calculation_duration_ms")
    private Long calculationDurationMs;

    /**
     * 计算算法版本
     */
    @Column(name = "calculation_algorithm_version", length = 32)
    private String calculationAlgorithmVersion;

    /**
     * 最后校验时间
     */
    @Column(name = "last_validation_time")
    private LocalDateTime lastValidationTime;

    /**
     * 校验状态：VALID（有效）、INVALID（无效）、PENDING（待校验）
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "validation_status", length = 16)
    private ValidationStatus validationStatus;

    /**
     * 是否为基准数据
     */
    @Column(name = "is_benchmark_data")
    private Boolean isBenchmarkData;

    /**
     * 基准描述
     */
    @Column(name = "benchmark_description", length = 500)
    private String benchmarkDescription;

    /**
     * 是否发布
     */
    @Column(name = "is_published")
    private Boolean isPublished;

    /**
     * 发布时间
     */
    @Column(name = "published_time")
    private LocalDateTime publishedTime;

    /**
     * 扩展属性（JSON格式）
     */
    @Column(name = "additional_attributes", length = 2000, columnDefinition = "TEXT")
    private String additionalAttributes;

    /**
     * 创建时间
     */
    @Column(name = "created_time", nullable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 版本号（用于乐观锁）
     */
    @Version
    @Column(name = "version", nullable = false)
    private Integer version;
}